package org.springblade.modules.admin.controller;

import org.springblade.core.tool.api.R;
import org.springblade.core.tool.utils.Func;
import org.springblade.modules.admin.dto.ElevatorDeviceSaveBathDTO;
import org.springblade.modules.admin.entity.Building;
import org.springblade.modules.admin.entity.ElevatorDevice;
import org.springblade.modules.admin.service.ElevatorDeviceService;
import org.springblade.modules.admin.vo.*;
import org.springframework.web.bind.annotation.*;
import com.baomidou.mybatisplus.core.metadata.IPage;
import lombok.AllArgsConstructor;
import org.springblade.core.boot.ctrl.BladeController;
import org.springblade.core.mp.support.Condition;
import org.springblade.core.mp.support.Query;
import org.springblade.core.tenant.annotation.TenantIgnore;
import org.springblade.modules.admin.service.ElevatorService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;


/**
 * @Date 16:05 2022/5/10
 * @Description {
 *   电梯体联网设备
 * }
 * @Author lsay
 **/
@AllArgsConstructor
@RequestMapping("/elevator/device")
@RestController
public class ElevatorDeviceController extends BladeController {

	private final ElevatorDeviceService elevatorDeviceService;

	private final ElevatorService elevatorService;

	/**
	 * 添加或更新电梯关联梯联网设备ID
	 * @param elevatorDevice
	 * @return
	 */
	@PostMapping("/saveOrUpdate")
	public R<Boolean> saveOrUpdate(@RequestBody ElevatorDevice elevatorDevice){
		return R.data(elevatorDeviceService.saveOrUpdateElevatorDevice(elevatorDevice));
	}

	/**
	 * 批量添加或更新电梯关联梯联网设备ID
	 * @param saveBathDTO
	 * @return
	 */
	@PostMapping("/saveOrUpdateBath")
	public R<Boolean> saveBath(@RequestBody List<ElevatorDevice> saveBathDTO){
		return R.data(elevatorDeviceService.saveOrUpdateElevatorDeviceList(saveBathDTO));
	}

	/**
	 * 解除电梯关联梯联网设备ID
	 * @param elevatorIds
	 * @return
	 */
	@DeleteMapping("/remove")
	public R<Boolean> remove(String elevatorIds) {
		return R.data(elevatorDeviceService.removeElevatorDevice(Func.toLongList(elevatorIds)));
	}

	@TenantIgnore
	@GetMapping("/page")
	public R<IPage<ElevatorPageVO>> page(ElevatorSearchVO search, Query query) {
		return R.data(elevatorService.devicePage(Condition.getPage(query), search));
	}

	@TenantIgnore
	@GetMapping("/building/page")
	public R<IPage<BuildingVO>> buildingPage(Building building, Query query) {
		return R.data(elevatorDeviceService.buildingPage(Condition.getPage(query), building));
	}

	@TenantIgnore
	@GetMapping("/building/select/devices")
	public R<List<BuildingSelectListVO>> buildingSelectDevices() {
		return R.data(elevatorDeviceService.buildingSelectDevices());
	}
}
